package com.qyhl.webtv.module_live.teletext.newchatroom;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.basiclib.utils.glide.GlideCircleTransform;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.live.TeleTextMessageBean;
import com.qyhl.webtv.module_live.R;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class ChatRoomMyView implements ItemViewDelegate<TeleTextMessageBean> {
    private Context context;

    public ChatRoomMyView(Context context) {
        this.context = context;
    }

    @Override
    public int getItemViewLayoutId() {
        return R.layout.live_item_teletext_comment_me;
    }

    @Override
    public boolean isForViewType(TeleTextMessageBean textMessageBean, int i) {
        String userName = CommonUtils.getInstance().getUserName();
        return textMessageBean.getUsername().equalsIgnoreCase(userName);
    }

    @Override
    public void convert(ViewHolder viewHolder, TeleTextMessageBean textMessageBean, int i) {
        viewHolder.setText(R.id.item_content, textMessageBean.getMessage());
        viewHolder.setText(R.id.nickName, StringUtils.encodePhoneNum(textMessageBean.getNickname()));
        ImageView img = viewHolder.getView(R.id.my_icon);
        Glide.with(context)
                .load(textMessageBean.getLogo())
                .apply(new RequestOptions().transform(new GlideCircleTransform(context)).placeholder(R.drawable.comment_head_default).error(R.drawable.comment_head_default).transform(new GlideCircleTransform(context)))
                .into(img);
    }
}
